package demo3;

import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        //test1();
        //test2();
        test3();
    }
    public static void test1() {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        System.out.println(arrayList);
        List<String> list = new ArrayList<>();//向上转型
        list.add("Hello");
        list.add("World");
        System.out.println(list);
    }
    public static void test2() {
        ArrayList<Integer> arrayList = new ArrayList<>(20);
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);
        System.out.println(arrayList);
    }
    public static void test3() {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        System.out.println(arrayList);
        ArrayList<Integer> arrayList1 = new ArrayList<>(arrayList);
        arrayList1.add(10);
        System.out.println(arrayList1);
        ArrayList<Number> arrayList2 = new ArrayList<>(arrayList);
        arrayList2.add(100);
        System.out.println(arrayList2);
        System.out.println(arrayList1);
        //ArrayList<String> stringArrayList = new ArrayList<>(arrayList);//报错
    }
}
